package cn.tansanqinger.controller.knowledge;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.tansanqinger.pojo.Knowledge;
import cn.tansanqinger.service.catalogue.ICatalogueService;
import cn.tansanqinger.service.hymenu.IHyMenuServer;
import cn.tansanqinger.service.knowledge.IKnowledgeService;
import cn.tansanqinger.util.PageData;
/**
 * 知识页面首页
 * @author C3H2
 * @time 12月
 */
@Controller
@RequestMapping("/knowledge")
public class KnowledgeController {

	@Autowired 
	public ICatalogueService service;
	@Autowired
	private IHyMenuServer hyMenuServer;
	@Autowired
	private IKnowledgeService kservice;
	
	@RequestMapping("/knowledge/{kid}")
	public String knowledgeIndex(@PathVariable("kid")String kid, Model model) throws Exception {
		//Map<String,Object> map = service.selectOnes(kid);
		model.addAttribute("message", service.selectOnes(kid));
		model.addAttribute("count", 1);
		return "second/knowledgeIndex";
	}
	
	@RequestMapping("/list")
	public ModelAndView list(HttpServletRequest request, ModelAndView mv) {
		mv = hyMenuServer.selectHyMenuAll(mv);
		mv.addObject("user", request.getSession().getAttribute("user"));
		mv.setViewName("knowledge/knowledgeIndex");
		Map<String, Object> map = service.selectOnes("1");
		mv.addObject("message", map.get("resultList"));
		mv.addObject("knowledge", map.get("knowledge"));
		mv.addObject("count", 1);
		return mv;
	}
	
	@RequestMapping("/user/mistake")
	@ResponseBody
	public PageData mistake(HttpServletRequest request) {
		return kservice.queryKnowledge(request);
	}
	
	
	@RequestMapping("/knowledgeShow")
	public String knowledgeShow(Model model) throws Exception {
		return "second/knowledgeShow";
	}
	
	@RequestMapping("/messagetoload")
	@ResponseBody
	public Knowledge messagetoload(HttpServletRequest request) {
		return kservice.selectOne(request);
	}
}
